<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML布局复制到公众号的完美解决方案</title>
    <script src="../js/html2canvas.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
            line-height: 1.6;
            color: #333;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            padding: 20px;
            min-height: 100vh;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            border-radius: 20px;
            box-shadow: 0 15px 40px rgba(0, 0, 0, 0.12);
            overflow: hidden;
        }
        
        /* 浮动工具栏 */
        .toolbar {
            position: fixed;
            right: 30px;
            top: 50%;
            transform: translateY(-50%);
            display: flex;
            flex-direction: column;
            gap: 15px;
            z-index: 1000;
        }
        .toolbar-btn {
            background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
            color: white;
            border: none;
            padding: 15px 20px;
            border-radius: 50px;
            cursor: pointer;
            font-size: 14px;
            font-weight: bold;
            box-shadow: 0 6px 20px rgba(106, 17, 203, 0.3);
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 10px;
            min-width: 140px;
        }
        .toolbar-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 25px rgba(106, 17, 203, 0.4);
        }
        .toolbar-btn:active {
            transform: translateY(0);
        }
        .toolbar-btn.reset {
            background: linear-gradient(135deg, #ff6b6b 0%, #ff8e8e 100%);
            box-shadow: 0 6px 20px rgba(255, 107, 107, 0.3);
        }
        
        /* 响应式设计 */
        @media (max-width: 768px) {
            .toolbar {
                position: fixed;
                bottom: 20px;
                top: auto;
                right: 20px;
                left: 20px;
                flex-direction: row;
                justify-content: space-around;
                transform: none;
            }
            .toolbar-btn {
                flex: 1;
                padding: 12px 15px;
                font-size: 12px;
                min-width: auto;
            }
        }
        
        /* 文章内容样式 */
        header {
            background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
            color: white;
            padding: 50px 30px;
            text-align: center;
            position: relative;
        }
        header::after {
            content: "";
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            height: 10px;
            background: linear-gradient(90deg, 
                #ff9a9e 0%, 
                #fad0c4 20%, 
                #a1c4fd 40%, 
                #c2e9fb 60%, 
                #d4fc79 80%, 
                #96e6a1 100%);
        }
        h1 {
            font-size: 32px;
            margin-bottom: 15px;
            text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
            letter-spacing: 1px;
        }
        .subtitle {
            font-size: 18px;
            opacity: 0.9;
            margin-bottom: 20px;
            text-align: center;
        }
        .content {
            padding: 40px 30px;
        }
        .intro {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 25px;
            border-radius: 15px;
            margin-bottom: 30px;
            box-shadow: 0 8px 20px rgba(240, 147, 251, 0.3);
            position: relative;
            overflow: hidden;
        }
        .intro::before {
            content: "";
            position: absolute;
            top: -50%;
            right: -50%;
            width: 100%;
            height: 100%;
            background: rgba(255, 255, 255, 0.1);
            transform: rotate(30deg);
        }
        .intro p {
            font-size: 18px;
            position: relative;
            z-index: 1;
        }
        h2 {
            color: #2c3e50;
            margin: 35px 0 20px;
            padding-bottom: 12px;
            border-bottom: 2px solid #f0f2f5;
            position: relative;
        }
        h2::after {
            content: "";
            position: absolute;
            bottom: -2px;
            left: 0;
            width: 80px;
            height: 3px;
            background: linear-gradient(90deg, #6a11cb, #2575fc);
            border-radius: 3px;
        }
        h3 {
            color: #3498db;
            margin: 25px 0 15px;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        p {
            margin-bottom: 18px;
            text-align: justify;
        }
        .method {
            background: white;
            border-radius: 15px;
            padding: 25px;
            margin-bottom: 25px;
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
            border: 1px solid #f0f2f5;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }
        .method::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 5px;
            height: 100%;
            background: linear-gradient(to bottom, #6a11cb, #2575fc);
        }
        .method:hover {
            transform: translateY(-5px);
            box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
        }
        .method-icon {
            width: 40px;
            height: 40px;
            background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
            font-size: 18px;
            box-shadow: 0 4px 10px rgba(106, 17, 203, 0.3);
        }
        .pros-cons {
            display: flex;
            gap: 20px;
            margin-top: 20px;
        }
        .pros, .cons {
            flex: 1;
            padding: 20px;
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
        }
        .pros {
            background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
            border-left: 4px solid #4caf50;
        }
        .cons {
            background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
            border-left: 4px solid #f44336;
        }
        ul, ol {
            margin: 12px 0 18px 25px;
        }
        li {
            margin-bottom: 10px;
            position: relative;
        }
        li::before {
            content: "•";
            color: #6a11cb;
            font-weight: bold;
            position: absolute;
            left: -15px;
        }
        .steps {
            background: linear-gradient(135deg, #f5f7fa 0%, #e4edf5 100%);
            padding: 20px;
            border-radius: 12px;
            margin: 20px 0;
            border: 1px solid #e1e8ed;
        }
        .step {
            display: flex;
            margin-bottom: 15px;
            align-items: flex-start;
        }
        .step-num {
            background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
            color: white;
            width: 30px;
            height: 30px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 15px;
            flex-shrink: 0;
            font-weight: bold;
            box-shadow: 0 4px 8px rgba(106, 17, 203, 0.3);
        }
        .tip-box {
            background: linear-gradient(135deg, #fff8e1 0%, #ffecb3 100%);
            border: 1px solid #ffd54f;
            border-radius: 12px;
            padding: 20px;
            margin: 25px 0;
            position: relative;
            overflow: hidden;
        }
        .tip-box::before {
            content: "💡";
            position: absolute;
            top: 10px;
            right: 15px;
            font-size: 24px;
            opacity: 0.3;
        }
        .tip-box h4 {
            color: #ff9800;
            margin-bottom: 10px;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .comparison {
            display: flex;
            gap: 20px;
            margin: 30px 0;
        }
        .comparison-item {
            flex: 1;
            padding: 25px;
            border-radius: 15px;
            text-align: center;
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
            transition: all 0.3s ease;
        }
        .comparison-item:hover {
            transform: translateY(-5px);
        }
        .recommended {
            background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
            border: 2px solid #2196f3;
            position: relative;
            overflow: hidden;
        }
        .recommended::after {
            content: "推荐";
            position: absolute;
            top: 15px;
            right: -30px;
            background: #2196f3;
            color: white;
            padding: 5px 30px;
            transform: rotate(45deg);
            font-size: 12px;
        }
        .conclusion {
            background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
            padding: 30px;
            border-radius: 15px;
            margin-top: 40px;
            text-align: center;
            box-shadow: 0 8px 25px rgba(76, 175, 80, 0.15);
            position: relative;
            overflow: hidden;
        }
        .conclusion::before {
            content: "";
            position: absolute;
            top: -50%;
            left: -50%;
            width: 100%;
            height: 100%;
            background: rgba(255, 255, 255, 0.2);
            transform: rotate(30deg);
        }
        .conclusion h2, .conclusion p {
            position: relative;
            z-index: 1;
        }
        footer {
            text-align: center;
            padding: 25px;
            background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
            color: white;
            margin-top: 40px;
        }

        /* 文字缩放相关样式 */
        .text-zoom-small {
            font-size: 0.9em;
        }
        .text-zoom-large {
            font-size: 1.1em;
        }
        .text-zoom-xlarge {
            font-size: 1.2em;
        }
    </style>
</head>
<body>
    <!-- 浮动工具栏 -->
    <div class="toolbar">
        <button class="toolbar-btn" onclick="zoomIn()">
            <span>🔍</span> 文字放大
        </button>
        <button class="toolbar-btn" onclick="zoomOut()">
            <span>🔍</span> 文字缩小
        </button>
        <button class="toolbar-btn" onclick="exportToImage()">
            <span>📷</span> 导出长图
        </button>
        <button class="toolbar-btn reset" onclick="resetZoom()">
            <span>↺</span> 重置大小
        </button>
    </div>

    <div class="container" id="content-container" contenteditable="true">
        <header>
            <h1>HTML布局复制到公众号的完美解决方案</h1>
            <p class="subtitle">保持样式不变，让内容完美呈现</p>
        </header>
        
        <div class="content">
            <div class="intro">
                <p>你是否曾经遇到过这样的问题：精心设计的HTML布局文章，复制到公众号编辑器后样式全乱？本文将为你介绍三种实用方法，帮助你完美解决这一难题。</p>
            </div>
            
            <h2>为什么HTML布局在公众号中会失效？</h2>
            <p>微信公众号编辑器出于安全考虑，会过滤掉大部分HTML标签和CSS样式，只保留基本的内容格式。这意味着你精心设计的布局、颜色、字体等样式在复制后几乎都会丢失。</p>
            
            <h2>三种实用解决方案</h2>
            
            <div class="method">
                <h3><span class="method-icon">1</span>方法一：截图法（最简单）</h3>
                <p>将HTML内容渲染为图片，然后插入公众号文章。这种方法虽然简单，但能100%保持原始样式。</p>
                
                <div class="steps">
                    <div class="step">
                        <div class="step-num">1</div>
                        <div>将HTML内容在浏览器中打开并调整到合适大小</div>
                    </div>
                    <div class="step">
                        <div class="step-num">2</div>
                        <div>使用截图工具（如Snipaste、系统自带截图）截取内容</div>
                    </div>
                    <div class="step">
                        <div class="step-num">3</div>
                        <div>在公众号编辑器中插入截图图片</div>
                    </div>
                </div>
                
                <div class="pros-cons">
                    <div class="pros">
                        <h4>优点</h4>
                        <ul>
                            <li>100%保持原始样式</li>
                            <li>操作简单，无需技术背景</li>
                            <li>适用于任何复杂布局</li>
                            <li>兼容性最佳</li>
                        </ul>
                    </div>
                    <div class="cons">
                        <h4>缺点</h4>
                        <ul>
                            <li>文字无法复制和搜索</li>
                            <li>图片尺寸影响加载速度</li>
                            <li>内容更新需要重新截图</li>
                            <li>不适合长篇文章</li>
                        </ul>
                    </div>
                </div>
            </div>
            
            <div class="method">
                <h3><span class="method-icon">2</span>方法二：第三方工具转换</h3>
                <p>使用专门的公众号排版工具转换HTML代码，平衡效果与便利性。</p>
                
                <div class="steps">
                    <div class="step">
                        <div class="step-num">1</div>
                        <div>复制HTML代码</div>
                    </div>
                    <div class="step">
                        <div class="step-num">2</div>
                        <div>在第三方编辑器（如135编辑器、秀米）中粘贴HTML</div>
                    </div>
                    <div class="step">
                        <div class="step-num">3</div>
                        <div>工具会自动转换为公众号兼容格式</div>
                    </div>
                    <div class="step">
                        <div class="step-num">4</div>
                        <div>从第三方编辑器复制内容到公众号编辑器</div>
                    </div>
                </div>
                
                <div class="pros-cons">
                    <div class="pros">
                        <h4>优点</h4>
                        <ul>
                            <li>保留可编辑文本</li>
                            <li>文字可复制和搜索</li>
                            <li>能还原大部分样式</li>
                            <li>操作相对简单</li>
                        </ul>
                    </div>
                    <div class="cons">
                        <h4>缺点</h4>
                        <ul>
                            <li>复杂样式可能无法完美还原</li>
                            <li>需要依赖第三方工具</li>
                            <li>转换效果因工具而异</li>
                            <li>可能需要付费高级功能</li>
                        </ul>
                    </div>
                </div>
            </div>
            
            <div class="method">
                <h3><span class="method-icon">3</span>方法三：手动重构代码</h3>
                <p>将HTML重写为公众号兼容的格式，实现最佳控制效果。</p>
                
                <div class="steps">
                    <div class="step">
                        <div class="step-num">1</div>
                        <div>分析原始布局结构</div>
                    </div>
                    <div class="step">
                        <div class="step-num">2</div>
                        <div>使用公众号支持的HTML标签和CSS样式重写</div>
                    </div>
                    <div class="step">
                        <div class="step-num">3</div>
                        <div>在公众号HTML模式下粘贴代码</div>
                    </div>
                    <div class="step">
                        <div class="step-num">4</div>
                        <div>预览并微调效果</div>
                    </div>
                </div>
                
                <div class="pros-cons">
                    <div class="pros">
                        <h4>优点</h4>
                        <ul>
                            <li>精确控制最终效果</li>
                            <li>文字可复制和搜索</li>
                            <li>可实现复杂排版</li>
                            <li>不依赖第三方工具</li>
                        </ul>
                    </div>
                    <div class="cons">
                        <h4>缺点</h4>
                        <ul>
                            <li>技术门槛高</li>
                            <li>耗时耗力</li>
                            <li>需要反复测试</li>
                            <li>学习成本较高</li>
                        </ul>
                    </div>
                </div>
            </div>
            
            <div class="tip-box">
                <h4>💡 公众号HTML/CSS支持要点</h4>
                <ul>
                    <li>使用<strong>内联样式</strong>，避免外部CSS</li>
                    <li>基本标签：div, p, span, img, a, strong等</li>
                    <li>布局：推荐使用table布局或简单div</li>
                    <li>单位：使用px，避免rem/vw等响应式单位</li>
                    <li>图片：必须先上传到公众号获取URL</li>
                    <li>颜色：使用十六进制或RGB值</li>
                    <li>字体：使用系统默认字体栈</li>
                </ul>
            </div>
            
            <h2>方法对比与选择建议</h2>
            <div class="comparison">
                <div class="comparison-item">
                    <h3>截图法</h3>
                    <p>适合：静态内容、图表、流程图</p>
                    <p>难度：★☆☆☆☆</p>
                    <p>效果：★★★★★</p>
                </div>
                <div class="comparison-item recommended">
                    <h3>第三方工具</h3>
                    <p>适合：大部分文章内容</p>
                    <p>难度：★★☆☆☆</p>
                    <p>效果：★★★★☆</p>
                </div>
                <div class="comparison-item">
                    <h3>手动重构</h3>
                    <p>适合：专业排版需求</p>
                    <p>难度：★★★★★</p>
                    <p>效果：★★★★★</p>
                </div>
            </div>
            
            <div class="conclusion">
                <h2>总结</h2>
                <p>对于大多数用户，我们推荐使用<strong>方法二：第三方工具转换</strong>，它在效果和便利性之间取得了良好平衡。</p>
                <p>如果只是简单分享静态内容，<strong>方法一：截图法</strong>是最简单可靠的选择。</p>
                <p>只有在对排版有极高要求且有前端技术能力时，才考虑<strong>方法三：手动重构</strong>。</p>
                <p style="margin-top: 15px;"><strong>最后提醒：</strong>无论使用哪种方法，发布前务必在手机上预览最终效果！</p>
            </div>
        </div>
        
        <footer>
            <p>实用技巧与解决方案</p>
        </footer>
    </div>

    <script>
        let currentZoomLevel = 0; 
        const zoomLevels = ['', 'text-zoom-small', '', 'text-zoom-large', 'text-zoom-xlarge'];
        
        function zoomIn() {
            if (currentZoomLevel < 4) {
                currentZoomLevel++;
                applyTextZoom();
                showNotification('文字已放大');
            }
        }
        
        function zoomOut() {
            if (currentZoomLevel > 0) {
                currentZoomLevel--;
                applyTextZoom();
                showNotification('文字已缩小');
            }
        }
        
        function resetZoom() {
            currentZoomLevel = 0;
            applyTextZoom();
            showNotification('已重置文字大小');
        }
        
        function applyTextZoom() {
            const content = document.querySelector('.content');
            
            // 移除所有缩放类
            content.classList.remove('text-zoom-small', 'text-zoom-large', 'text-zoom-xlarge');
            
            // 添加当前缩放类
            if (zoomLevels[currentZoomLevel]) {
                content.classList.add(zoomLevels[currentZoomLevel]);
            }
            
            // 更新工具栏按钮状态
            updateToolbarButtons();
        }
        
        function updateToolbarButtons() {
            const zoomInBtn = document.querySelector('.toolbar-btn:nth-child(1)');
            const zoomOutBtn = document.querySelector('.toolbar-btn:nth-child(2)');
            
            // 更新放大按钮状态
            if (currentZoomLevel >= 4) {
                zoomInBtn.disabled = true;
                zoomInBtn.style.opacity = '0.5';
            } else {
                zoomInBtn.disabled = false;
                zoomInBtn.style.opacity = '1';
            }
            
            // 更新缩小按钮状态
            if (currentZoomLevel <= 0) {
                zoomOutBtn.disabled = true;
                zoomOutBtn.style.opacity = '0.5';
            } else {
                zoomOutBtn.disabled = false;
                zoomOutBtn.style.opacity = '1';
            }
        }
        
        function exportToImage() {
            const container = document.getElementById('content-container');
            
            // 显示加载提示
            showNotification('正在生成图片，请稍候...');
            
            // 隐藏工具栏避免出现在截图中
            const toolbar = document.querySelector('.toolbar');
            toolbar.style.display = 'none';
            
            html2canvas(container, {
                scale: 2,
                useCORS: true,
                scrollY: -window.scrollY,
                backgroundColor: '#ffffff'
            }).then(canvas => {
                // 显示工具栏
                toolbar.style.display = 'flex';
                
                // 创建下载链接
                const link = document.createElement('a');
                link.download = '公众号文章截图.png';
                link.href = canvas.toDataURL('image/png');
                link.click();
                
                showNotification('图片已生成并开始下载');
            }).catch(error => {
                // 显示工具栏
                toolbar.style.display = 'flex';
                showNotification('生成图片时出错，请重试');
                console.error('导出图片错误:', error);
            });
        }
        
        function showNotification(message) {
            // 移除已存在的通知
            const existingNotification = document.querySelector('.notification');
            if (existingNotification) {
                existingNotification.remove();
            }
            
            // 创建新通知
            const notification = document.createElement('div');
            notification.className = 'notification';
            notification.textContent = message;
            notification.style.cssText = `
                position: fixed;
                top: 20px;
                left: 50%;
                transform: translateX(-50%);
                background: rgba(0, 0, 0, 0.8);
                color: white;
                padding: 12px 20px;
                border-radius: 5px;
                z-index: 10000;
                font-size: 14px;
                transition: opacity 0.3s;
            `;
            
            document.body.appendChild(notification);
            
            // 3秒后自动移除
            setTimeout(() => {
                notification.style.opacity = '0';
                setTimeout(() => {
                    if (notification.parentNode) {
                        notification.parentNode.removeChild(notification);
                    }
                }, 300);
            }, 3000);
        }
        
        // 键盘快捷键
        document.addEventListener('keydown', function(e) {
            if (e.ctrlKey) {
                if (e.key === '=' || e.key === '+') {
                    e.preventDefault();
                    zoomIn();
                } else if (e.key === '-') {
                    e.preventDefault();
                    zoomOut();
                } else if (e.key === '0') {
                    e.preventDefault();
                    resetZoom();
                } else if (e.key === 's') {
                    e.preventDefault();
                    exportToImage();
                }
            }
        });
        
        // 初始化按钮状态
        updateToolbarButtons();
    </script>
</body>
</html>